// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   InstituteProfileDAO.java

package com.nervytech.tutorcruise.db.dao.mysql.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import com.nervytech.tutorcruise.db.dao.interfaces.IInstituteProfileDAO;
import com.nervytech.tutorcruise.db.dao.model.InstituteProfile;

@Repository("instituteProfileDAO")
public class InstituteProfileDAO extends JdbcDaoSupport implements
		IInstituteProfileDAO {

	@Autowired
	InstituteProfileDAO(DataSource dataSource) {
		setDataSource(dataSource);
	}

	public void saveInstituteProfile(InstituteProfile instituteprofile) {
	}

	public List getInstituteProfile(long userId) {
		RowMapper mapper = new RowMapper() {

			public InstituteProfile mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				InstituteProfile instProfile = new InstituteProfile();
				instProfile.setAboutInstitute(rs.getString("abount_institute"));
				instProfile.setAddress(rs.getString("address"));
				instProfile.setPhone(rs.getString("phone"));
				instProfile.setWebsite(rs.getString("website"));
				instProfile.setTaggedSkills(rs.getString("tagged_skills"));
				instProfile.setCertifications(rs.getString("certifications"));
				instProfile.setCoursesOffered(rs.getString("courses_offered"));
				instProfile.setRating(rs.getShort("rating"));
				instProfile.setIsPortalCertified(rs
						.getShort("is_portal_certified"));
				instProfile
						.setIsTechCertified(rs.getShort("is_tech_certified"));
				instProfile.setFullName(rs.getString("full_name"));
				instProfile.setUserType(rs.getInt("user_type"));
				instProfile.setUserStatus(rs.getInt("user_status"));
				instProfile.setCategory(rs.getInt("category"));
				instProfile.setCity(rs.getInt("city"));
				instProfile.setZipCode(rs.getString("zip_code"));
				instProfile.setImageUrl(rs.getString("image_url"));
				instProfile.setContactNumber(rs.getString("contact_number"));
				System.out.println("RETURNING PROFILEEEEEEEEEEEEEEEE ");
				return instProfile;
			}

		};
		String selectUserQuery = (new StringBuilder(
				"SELECT u.full_name,u.user_type,u.user_status,u.city,u.category,u.zip_code, u.image_url,u.contact_number,u.mobile_verified,ip.phone,ip.website,ip.address,ip.tagged_skills,ip.certifications, ip.about_institute,ip.courses_offered,ip.rating,ip.is_portal_certified,ip.is_tech_certified FROM INSTITUTE_PROFILE ip ,USER u WHERE u.user_id="))
				.append(userId).append(" and ip.user_id=u.user_id").toString();
		logger.debug((new StringBuilder("Select user Query : ")).append(
				selectUserQuery).toString());
		return getJdbcTemplate().query(selectUserQuery, mapper);
	}

	public void updateInstituteProfile(InstituteProfile instituteprofile) {
	}

	public void updateFirstLogin(long userId, String phone, String website,
			String address) {
		String saveUserQuery = "update institute_profile set phone=?, website=?, address=? where user_id=?";
		Object parms[] = { phone, website, address, Long.valueOf(userId) };
		getJdbcTemplate().update(saveUserQuery, parms);
	}
}
